package com.sjy.web.controller.ship;

import com.sjy.common.annotation.Log;
import com.sjy.common.core.controller.BaseController;
import com.sjy.common.core.domain.AjaxResult;
import com.sjy.common.core.page.TableDataInfo;
import com.sjy.common.enums.BusinessType;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.ship.domain.ElectronicCoupon;
import com.sjy.ship.domain.vo.ShipEcVo;
import com.sjy.ship.service.IElectronicCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电子联单Controller
 * 
 * @author lzm
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/ship/coupon")
public class ElectronicCouponController extends BaseController
{
    @Autowired
    private IElectronicCouponService shipElectronicCouponService;

    /**
     * 查询船舶电子联单登记列表
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElectronicCoupon electronicCoupon)
    {
        startPage();
        List<ShipEcVo> list = shipElectronicCouponService.selectShipEcVoList(electronicCoupon);
        return getDataTable(list);
    }


    /**
     * 导出船舶电子联单登记列表
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:export')")
    @Log(title = "电子联单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectronicCoupon electronicCoupon)
    {
        List<ShipEcVo> list = shipElectronicCouponService.selectShipEcVoList(electronicCoupon);
        ExcelUtil<ShipEcVo> util = new ExcelUtil<ShipEcVo>(ShipEcVo.class);
        util.exportExcel(response, list, "电子联单数据");
    }

    /**
     * 获取电子联单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:query')")
    @GetMapping(value = "/{shipEcNo}")
    public AjaxResult getInfo(@PathVariable("shipEcNo") Long shipEcNo)
    {
        return success(shipElectronicCouponService.selectElectronicCouponByEcNo(shipEcNo));
    }

    /**
     * 新增电子联单
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:add')")
    @Log(title = "电子联单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ElectronicCoupon electronicCoupon)
    {
        return toAjax(shipElectronicCouponService.insertElectronicCoupon(electronicCoupon));
    }

    /**
     * 修改电子联单
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:edit')")
    @Log(title = "电子联单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ElectronicCoupon electronicCoupon)
    {
        return toAjax(shipElectronicCouponService.updateElectronicCoupon(electronicCoupon));
    }

    /**
     * 删除电子联单
     */
    @PreAuthorize("@ss.hasPermi('ship:coupon:remove')")
    @Log(title = "电子联单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shipEcNos}")
    public AjaxResult remove(@PathVariable Long[] shipEcNos)
    {
        return toAjax(shipElectronicCouponService.deleteElectronicCouponByEcNos(shipEcNos));
    }
}
